import { setLastUrl, isLogin } from '@/utils/util.js'
import { Message } from 'element-ui'

let loginRouter = [
  '/company/companySpace'
] // 需要登录的页面

// 路由守卫
export default function(router) {
  router.beforeEach((to, from, next) => {
    let lr = loginRouter.find(e => e == to.fullPath)
    if(lr && !isLogin()) {
      Message.error("您需要登录才能访问当前页面，请先登录")
      setLastUrl(lr)
      next({ path: '/login' })
    } else {
      next()
    }
  })
}
